﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="TechBits">
//   Copyright (c) TechBits. All rights reserved.
// </copyright>
// <author>
//   Leandro G. Vacirca
// </author>
// <summary>
//   Defines the MainForm type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace IntelliShortCut
{
    using System;
    using System.Windows.Forms;
    
    using Application;
    using Application.Helpers;
    using log4net.Config;
    using UI.Forms;

    /// <summary>
    /// The program manager. 
    /// </summary>
    public static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        [STAThread]
        public static void Main(string[] args)
        {
            // Setup the Log4net
            XmlConfigurator.Configure();            

            // Setup the global error handler
            ApplicationErrorHandler.Setup();

            // Checks if the application is on windows startup
            if (!ApplicationConfiguration.Settings.FirstRun)
            {
                WindowsStartUpHelper.Instance.AddApplicationToStartup(ApplicationConfiguration.Name, ApplicationConfiguration.FullPath);
                ApplicationConfiguration.Settings.FirstRun = true;

                // The first time the application runs, show the tips window
                var tipsForm = new TipsForm();
                tipsForm.Show();

                var result = MessageBox.Show(
                    "Do you want to search for shortcuts now? If you choose Yes the window of the Shortcuts Editor will show up and you will be able to search for shortcuts through the Search button. If you choose No, you can do this later.",
                    "First time run",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    var shortcutsEditor = new ShortcutsEditorForm();
                    shortcutsEditor.Show();
                }

                ApplicationConfiguration.SaveSettings();
            }

            // Process the input arguments
            ShortcutApl.ProcessArguments(args);

            // Run a single instance of the application
            SingleInstanceHelper.ProxyMain(typeof(MainForm), ApplicationConfiguration.MainWindowName);
        }
    }
}
